<%@ page language="java" import="java.sql.*" contentType="text/html; charset=utf-8" %>

<%!
public static String change_Code(String line, String oldString, String newString){
   	for(int index = 0; (index = line.indexOf(oldString, index)) >= 0; index += newString.length())
       	line = line.substring(0, index) + newString + line.substring(index + oldString.length());
    return line;
}
%>

<HTML>
<HEAD>
<TITLE>▒▒ 게시판 ▒▒</TITLE>

<style type="text/css">
<!--
  .table {font-size:9pt; font-family : 돋움 ;font-weight:bold;color:white;background:#6699CC; }
a {text-decoration: none; }
  td	{ font-size : 10pt ; font-family : 돋움 ; font-decoration : none ;}
  font	{ font-size : 10pt ; font-family : 돋움 ; font-decoration : none ; }
  #title{ font-size : 10pt ; font-family : 돋움 ; font-decoration : none ; font-weight : bold ; color : ffffff ;}
 .dform { font-family: 돋움 ; font-size:10pt;color:white;background:#6699CC;}
 .ldTable { border-bottom:#636363 solid 1px;border-color:white; padding-top:5px; padding-bottom:5px; padding-left:3px;
            padding-right:3px; font-size:9pt}
-->
</style>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</HEAD>

<BODY bgcolor="white" >

<%
 	String DB_URL = "jdbc:mysql://localhost:3306/bbs";
	String DB_USER = "root";
	String DB_PASSWORD = "root";
	String query=null;
	Connection conn = null;
    Statement stmt = null;
    Statement stmt2 = null;

	int hit=0;

	int idx=0;
	// 만약 view.jsp로 바로 들어왔을 때를 대비..
	if(request.getParameter("idx")=="") {
		response.sendRedirect("list.jsp");
	}else{
		idx = Integer.parseInt(request.getParameter("idx"));

	} 	

	ResultSet result = null;
	//ResultSet result2 = null;

	query="SELECT IDX,NAME,EMAIL,TITLE,CONTENT,date_format(MOMENT,'%Y-%m-%e'),PASSWORD,HIT FROM GUEST WHERE IDX ="+idx;
	String query2="UPDATE GUEST SET HIT=HIT+1 WHERE IDX="+idx;
	
	out.println(query);
	out.println(query2);

	String sName="", sEmail="", sTitle="", sContent="", sMoment="", sPwd="", sTo="";
    
	Class.forName("com.mysql.jdbc.Driver");
	conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
	
	stmt = conn.createStatement();
	stmt2 = conn.createStatement();
	stmt2.executeUpdate(query2);
	stmt2.close();

	result = stmt.executeQuery(query);

	if(result.next()) {
		idx = result.getInt(1);
		sName = result.getString(2);
		sEmail = result.getString(3);
		sTitle = result.getString(4);
		sContent = result.getString(5);
		sMoment = result.getString(6);
		sPwd = result.getString(7);
		hit = result.getInt(8);
		
		if(!sEmail.equals("")){
			sTo="<A href=mailto:"+sEmail+">"+sName+"</A>";
		}else{
			sTo=sName;
		}


		
	}
	result.close();
    stmt.close();
    conn.close();
%>

  
  <table width="602" border="0" cellspacing="0" cellpadding="0">
    <tr>
    </tr>
  </table>
  
  <table width="602" border="0" cellspacing="0" cellpadding="0">
    <tr>
    </tr>
    <tr>
      <td colspan="3" >
        
        <table border="0" width="505" cellpadding="0" cellspacing="0" align="center">
          <tr>
            <td>
              
              <table border="1" width="602" cellpadding="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF" >
                <tr align="middle">
                  <td width="100" height="25" bgcolor="#8EA2FF">
                    <div align="CENTER"><font face="돋움" size="2" color="#FFFFFF">글번호</font>
                    </div>
                  </td>
                  <td bgcolor="#F6F6F6" width="155"> <font color="#000000" size="2" face="돋움"><%=idx%> </font></td><!-- 여기 -->
                  <td width="100"  height="25" bgcolor="#8EA2FF">
                    <div align="CENTER"><font face="돋움" size="2" color="#FFFFFF">날짜</font>
                    </div>
                  </td>
                  <td bgcolor="#F6F6F6"><font color="#000000" size="2" face="돋움"><%=sMoment%></font></td><!-- 여기 -->
                </tr>
                <tr align="middle">
                  <td width="100"  height="25" bgcolor="#8EA2FF">
                    <div align="CENTER"><font face="돋움" size="2" color="#FFFFFF">작성자</font>
                    </div>
                  </td>
                  <td bgcolor="#F6F6F6"> <font color="#000000" size="2" face="돋움"><a href="<%=sTo%>"><%=sTo%></a></font></td><!-- 여기 -->
                  <td width="100"  height="25" bgcolor="#8EA2FF">
                    <div align="CENTER"><font face="돋움" size="2" color="#FFFFFF">조회수</font>
                    </div>
                  </td>
                  <td bgcolor="#F6F6F6" width="150"><font color="#000000" size="2" face="돋움"><%=hit%></font><!-- 여기 -->
                  </td>
                </tr>              
              </table>
              
            </td>
          </tr>
        <tr><td>&nbsp;</td></tr>
          <tr>
            <td height="100">
              
              <table border="1" width="602" cellpadding="5" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                <tr bgcolor="#8EA2FF">
                  <td align="middle" height="26"><font face="돋움" size="2" color="#FFFFFF"><b><font color="#FFFFFF">제목 :<%=sTitle%></font>&nbsp; </b></font><!-- 여기 -->
                  </td>
                </tr>
                <tr bgcolor="#F6F6F6" >
                  <td height="72"><font face="돋움" size="2"><%=sContent%></font><!-- 여기 -->
                  </td>
                </tr>
              </table>
              
        </table>           
        
      </td>
      </tr>      
     </table>
     
   <tr>
   <td>           
 </table>
 
 <p align="center">
  <table>
	  <tr>
	  	<td>	  		
            <a href= modify.jsp?idx=<%=idx%>><img src="image/modify.gif" border="0"></a>  <!-- 여기 -->      	                     
	  	</td>	  	
	  	<td>&nbsp;&nbsp;</td>
	  	<td>
	  		<a href="list.jsp"><img src="image/list.gif" border="0"></a>	  <!-- 여기 -->		
	  	</td>
	  	<td>&nbsp;&nbsp;</td>
	  	<td>

	  		<a href= delete.jsp?idx=<%=idx%>><img src="image/delete.gif" border="0"></a><!-- 여기 -->
	  	</td>
	  </tr>
  </table>
  </p>
</BODY>
</HTML>